<template>
  <el-dialog title="返修工单选择"
             v-if="showFlag"
             :visible.sync="showFlag"
             :modal=false
             width="80%"
             center
  >

    <el-card style="border-radius: 10px">

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="返修单号" prop="repairCode">
        <el-input
          v-model="queryParams.repairCode"
          placeholder="请输入返修单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">

    <el-row :gutter="10" class="mb8">
    </el-row>

    <el-table v-loading="loading" :data="returnrepairList" @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
      <el-table-column width="50" align="center" >
        <template v-slot="scope">
          <el-radio v-model="selectedRepairId" :label="scope.row.id" @change="handleRowChange(scope.row)">{{""}}</el-radio>
        </template>
      </el-table-column>
      <el-table-column label="返修单号" align="center" prop="repairCode" width="150"/>
      <el-table-column label="返修类型" align="center" prop="repairType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.return_repair_type" :value="scope.row.repairType"/>
        </template>
      </el-table-column>
      <el-table-column label="检验单编号" align="center" prop="qcCode" width="150"/>
      <el-table-column label="检验单关联单号" align="center" prop="qcSourceDocCode" width="150"/>
      <el-table-column label="检验单关联类型" align="center" prop="qcSourceDocType" />
      <el-table-column label="物料编码" align="center" prop="itemCode" width="150"/>
      <el-table-column label="物料名称" align="center" prop="itemName" width="150"/>
      <el-table-column label="规格型号" align="center" prop="specification" />
      <el-table-column label="单位" align="center" prop="unitOfMeasure" />
      <el-table-column label="批次号" align="center" prop="batchCode" width="150"/>
      <el-table-column label="返修数量" align="center" prop="reworkNum" />
      <el-table-column label="工艺路线编号" align="center" prop="routeCode" width="150"/>
      <el-table-column label="工艺路线名称" align="center" prop="routeName" width="150"/>
      <el-table-column label="计划完工日期" align="center" prop="plannedCompletionDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.plannedCompletionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  listReturnrepair,
  getReturnrepair,
  addReturnrepair,
  updateReturnrepair,
  lingList
} from "@/api/mes/rr/returnrepair";


export default {
  name: "repairselect",
  dicts: ['return_repair_status', 'return_repair_type'],
  data() {
    return {
      showFlag: false,
      optType: undefined,
      selectedRepairId: undefined,
      selectedRows: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 返修管理-返修工单表格数据
      returnrepairList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        repairCode: null,
        repairType: null,
        repairStatus: null,
        itemCode: null,
        itemName: null,      },
      // 表单参数
      form: {},
      // 表单校验

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 目前 查询返修管理-  FINISHED  排产版 APPROVING  CONFIRMED  FINISHED*/
    getList() {
      this.loading = true;
      lingList(this.queryParams).then(response => {
        this.returnrepairList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.showFlag = false;
      this.selectedRows='';
    },
    // 表单重置
    reset() {

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 单选选中数据
    handleRowChange(row) {
      if (row) {
        this.selectedRows = row;
      }
    },
    handleCurrent(row) {
      if (row) {
        this.selectedRows = row;
      }
    },
    handleRowDbClick(row){
      if(row){
        this.selectedRows = row;
        this.$emit('onSelected',this.selectedRows);
        this.showFlag = false;
      }
    },

    //确定选中
    confirmSelect() {
      if (this.selectedRepairId == null || this.selectedRepairId == 0) {
        this.$notify({
          title: '提示',
          type: 'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected', this.selectedRows);
      this.showFlag = false;
    }

  }
};
</script>
